package com.zhuxiaomei.mapper;

import com.zhuxiaomei.annotation.AutoFill;
import com.zhuxiaomei.entity.restaurant.RestaurantCategory;
import com.zhuxiaomei.enumeration.OperationType;
import com.zhuxiaomei.vo.restaurant.RestaurantCategoryVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;


/**
 * @author hxm
 * @date 2024/11/10 15:46
 * @description
 */
public interface RestaurantCategoryMapper extends Mapper<RestaurantCategory> {

    @Select("select id, category_name, status from restaurant_categories where status = #{status} and is_deleted = 0 order by sort asc ")
    List<RestaurantCategory> selectCategoriesByStatus(@Param("status") String status);

    @Select("select id, category_name, status from restaurant_categories where is_deleted = 0 order by sort asc")
    List<RestaurantCategoryVO> selectAllCategories();

    @AutoFill(OperationType.INSERT)
    Integer insertRestaurantCategory(RestaurantCategory restaurantCategory);

    @Select("select id from restaurant_categories where category_name = #{categoryName}")
    Long selectCategoryIdByCategoryName(@Param("categoryName") String categoryName);

    @Update("update restaurant_categories set status = #{status} where category_name = #{categoryName}")
    void updateStatusByCategoryName(@Param("status") Byte status, @Param("categoryName") String categoryName);

    @Select("select id, category_name, sort, status from restaurant_categories where category_name = #{categoryName}")
    RestaurantCategory selectCategoryByCategoryName(@Param("categoryName") String categoryName);

    @Delete("delete from restaurant_categories where category_name = #{categoryName}")
    Integer deleteByCategoryName(@Param("categoryName") String categoryName);
}
